package com.san.oms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.san.oms.dao.ScoreLevelDetailDao;
import com.san.oms.domain.ScoreLevelDetailDO;
import com.san.oms.service.ScoreLevelDetailService;
import com.san.oms.vo.ScoreLevelDetailVO;

@Service
public class ScoreLevelDetailServiceImpl implements ScoreLevelDetailService{

	@Autowired
	private ScoreLevelDetailDao dao;
	
	@Override
	public ScoreLevelDetailDO getById(Long id) {
		return dao.getById(id);
	}

	@Override
	public List<ScoreLevelDetailDO> list(Map<String, Object> map) {
			return dao.list(map);
		
	}

	@Override
	public int count(Map<String, Object> map) {
		return dao.count(map);
	}

	@Override
	public int save(ScoreLevelDetailVO scoreLevelDetailVO) {
		ScoreLevelDetailDO scoreLevelDetailDO = getByName(scoreLevelDetailVO.getLevelName(), scoreLevelDetailVO.getScoreId());
		if(scoreLevelDetailDO != null){
			return -1;//若返回值为-1，则表示输入的等级名称已经存在，不可重复输入
		}else if(scoreLevelDetailVO.getLevelDown() > scoreLevelDetailVO.getLevelUp()){
			return -2;//若返回值为-2，则表示输入的区间下限大于区间上限
		}else{
			String levelInterval = scoreLevelDetailVO.getLevelDown()+"~"+scoreLevelDetailVO.getLevelUp();
			scoreLevelDetailVO.setLevelInterval(levelInterval);
			return dao.save(scoreLevelDetailVO);
		}
	}

	@Override
	public int doEdit(ScoreLevelDetailVO scoreLevelDetailVO) {
		ScoreLevelDetailDO scoreLevelDetailDO = getByName(scoreLevelDetailVO.getLevelName(), scoreLevelDetailVO.getScoreId());
		if(scoreLevelDetailDO != null && !scoreLevelDetailDO.getLevelName().equals(scoreLevelDetailVO.getOldName())){
			return -1;//若返回值为-1，则表示修改的等级名称已经存在，不可重复输入
		}else if(scoreLevelDetailVO.getLevelDown() > scoreLevelDetailVO.getLevelUp()){
			return -2;//若返回值为-2，则表示输入的区间下限大于区间上限
		}else{
			String levelInterval = scoreLevelDetailVO.getLevelDown()+"~"+scoreLevelDetailVO.getLevelUp();
			scoreLevelDetailVO.setLevelInterval(levelInterval);
			return dao.doEdit(scoreLevelDetailVO);
		}
	}

	@Override
	public int remove(Long id) {
		return dao.remove(id);
	}

	@Override
	public ScoreLevelDetailDO getByName(String levelName, Long scoreId) {	
		return dao.getByName(levelName, scoreId);
	}

	@Override
	public int remove1(Long id) {
		return dao.remove1(id);
	}
	
	@Override
	public int batchRemove(Long[] ids) {
		return dao.batchRemove(ids);
	}

}
